package com.cnct.pagehelper.controller;

import com.cnct.pagehelper.model.User;
import com.cnct.pagehelper.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping("/userList.action")
    public String toIndex(@RequestParam(required = true, defaultValue = "1") Integer page, Model model) {

        PageHelper.startPage(page, 3);
        List<User> userList = userService.findAll();
        PageInfo<User> p = new PageInfo<>(userList);
        model.addAttribute("page", p);
        model.addAttribute("userList", userList);
        return "index";
    }
}
